<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
	<title>trist</title>
</head>

<body>
	<script>

		// 异步问题，浏览器是多线程的，js是单线程的 =》浏览器只分配了一个线程给js引擎渲染
		// 

		async function async1() {
			console.log('async1 start');
			await async2();
			console.log('async1 end');
		}

		async function async2() {
			console.log('async2');
		}

		console.log('script start');

		setTimeout(function () {
			console.log('setTimeout');
		}, 0)

		async1();

		new Promise(function (resolve) {
			console.log('promise1');
			resolve();
		}).then(function () {
			console.log('promise2');
		});

		console.log('script end');
		
		// script start
		// index4.html:16 async1 start
		// index4.html:22 async2
		// index4.html:34 promise1
		// index4.html:40 script end
		// 开始事件循环，执行微任务
		// index4.html:18 async1 end
		// index4.html:37 promise2
		// 执行宏任务
		// index4.html:28 setTimeout

	</script>
</body>

</html>